# -*- coding: utf-8 -*-
"""
Project: automation-api-project
Creator: jinsheng
Create time: 2021-11-29 16:25
IDE: PyCharm
Introduction: dw_unit_electric_ts表造数据
"""
from datetime import timedelta
from multiprocessing import Process
from threading import Thread
import random
from datetime import datetime
from common.hbaseDataOperate import HbaseOperate


def insert(start):
    hb = HbaseOperate(table_name='dw_unit_electric_ts_1')
    fmt_s = '%Y%m%d%H%M%S'
    for j in range(start + 1, start + 10):
        unit_id = str(100000000000000000 + j)
        tm = datetime(2021, 11, 1, 0, 0)
        efrt_actual_kvarh = 1000.00
        efat_actual_kwh = 5000.00
        for i in range(192):
            tm_res = str(tm.strftime(fmt_s))[::-1]
            data_source = random.randint(1, 2)
            data_type = random.randint(1, 3)
            pt_actual_kw = round(random.uniform(1000.0, 3000.0), 2)
            qt_actual_kvar = round(random.uniform(300.0, 600.0), 2)
            random_increase = round(random.uniform(10.0, 30.0), 2)
            row_key = tm_res + unit_id + str(random.randint(1, 3)) + 'mi15'
            data = {'cf:unit_id': unit_id, 'cf:data_time': str(tm.strftime(fmt_s)), 'cf:data_type': str(data_type),
                    'cf:pt_actual_kw': str(pt_actual_kw), 'cf:qt_actual_kvar': str(qt_actual_kvar),
                    'cf:efrt_actual_kvarh': str(efrt_actual_kvarh + random_increase),
                    'cf:efat_actual_kwh': str(efat_actual_kwh + random_increase),
                    'cf:data_source': str(data_source), 'cf:data_qa': '0', 'cf:update_time': str(tm),
                    'cf:frequency': 'mi15'}
            tm += timedelta(minutes=15)
            hb.insert_data(row_key, data)
            efat_actual_kwh += random_increase
            efrt_actual_kvarh += random_increase


def insert_one(start):
    hb = HbaseOperate(table_name='dw_unit_electric_ts')
    fmt_s = '%Y%m%d%H%M%S'
    tm = datetime(2021, 11, 1, 0, 0)
    unit_id = str(100000000000000000 + start)
    efrt_actual_kvarh = 1000.00
    efat_actual_kwh = 5000.00
    for i in range(200):
        tm_res = str(tm.strftime(fmt_s))[::-1]
        data_source = random.randint(1, 2)
        data_type = random.randint(1, 3)
        pt_actual_kw = round(random.uniform(1000.0, 3000.0), 2)
        qt_actual_kvar = round(random.uniform(300.0, 600.0), 2)
        random_increase = round(random.uniform(10.0, 30.0), 2)
        row_key = tm_res + unit_id + 'mi15'
        data = {'cf:unit_id': unit_id, 'cf:data_time': str(tm.strftime(fmt_s)), 'cf:data_type': str(data_type),
                'cf:pt_actual_kw': str(pt_actual_kw), 'cf:qt_actual_kvar': str(qt_actual_kvar),
                'cf:efrt_actual_kvarh': str(efrt_actual_kvarh + random_increase),
                'cf:efat_actual_kwh': str(efat_actual_kwh + random_increase),
                'cf:data_source': str(data_source), 'cf:frequency': 'mi15'}
        tm += timedelta(minutes=15)
        hb.insert_data(row_key, data)
        efat_actual_kwh += random_increase
        efrt_actual_kvarh += random_increase


if __name__ == '__main__':
    insert(0)
